﻿namespace ScrumFactory.Services.Web
{
    using System.ComponentModel.Composition.Extensions;
    using System.ComponentModel.Composition.Hosting;
    using System.Reflection;
    using System.ServiceModel.Activation;
    using System.Web.Routing;

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new DirectoryCatalog(Server.MapPath("~/Bin"), "ScrumFactory.*.dll"));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new ConfigurationCatalog());
            catalog.Catalogs.Add(new ConnectionStringCatalog());

            var container = new CompositionContainer(catalog);

            var strings = container.GetExportedValue<string>("ScrumFactoryEntitiesConnectionString");

            RouteTable.Routes.Add(new ServiceRoute("ProjectsService", new MefWebServiceHostFactory(container), typeof(IProjectsService)));
            RouteTable.Routes.Add(new ServiceRoute("BacklogService", new MefWebServiceHostFactory(container), typeof(IBacklogService)));
            RouteTable.Routes.Add(new ServiceRoute("TeamService", new MefWebServiceHostFactory(container), typeof(ITeamService)));
        }
    }
}